package com.test.demo1.controller;

import com.test.demo1.bean.Projects;
import com.test.demo1.common.PageRequest;
import com.test.demo1.common.ResponseResult;
import com.test.demo1.service.ProjectsService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 项目信息表(Projects)表控制层
 *
 * @author makejava
 * @since 2025-07-22 23:11:50
 */
@RestController
@RequestMapping("projects")
public class ProjectsController {
    /**
     * 服务对象
     */

    private final ProjectsService projectsService;
public ProjectsController(ProjectsService projectsService){
        this.projectsService=projectsService;
}
    /**
     * 全量查询
     *
     * @param projects 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @PostMapping("queryAll")
    public List<Projects> queryAll(@RequestBody Projects projects) {
        return this.projectsService.queryAll(projects);
}
    /**
     * 分页查询
     *
     * @param projects 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @PostMapping("queryByPage")
    public PageInfo<Projects> queryByPage(@RequestBody PageRequest<Projects> projects) {
        return this.projectsService.queryByPage(projects);
}
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseResult<Projects> queryById(@PathVariable("id") Integer id) {
        return ResponseResult.ok(this.projectsService.queryById(id));
}
    /**
     * 查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("/query")
    public ResponseResult<Projects> queryOne(@RequestBody Projects projects) {
        return ResponseResult.ok(this.projectsService.selectOne(projects));
}

    /**
     * 新增数据
     *
     * @param projects 实体
     * @return 新增结果
     */
    @PostMapping("saveOrUpdate")
    public ResponseResult<Projects> saveOrUpdate(@RequestBody Projects projects) {
    this.projectsService.saveOrUpdate(projects);
        return ResponseResult.ok();
}


    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete/{id}")
    public ResponseResult<Boolean> deleteById(@PathVariable("id") Integer id) {
    this.projectsService.deleteByPrimaryKey(id);
        return ResponseResult.ok();
}

}

